package com.ruoyi.web.controller.buy;

import com.ruoyi.buy.domain.entity.PO.BuyProductItem;
import com.ruoyi.buy.domain.entity.buy0006.BuyProductItemImport;
import com.ruoyi.buy.domain.entity.importPO.BuyBatchPurchaseBillImport;
import com.ruoyi.buy.service.IBuyProductItemService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 投产登记Controller
 * 
 * @author ruoyi
 * @date 2024-04-23
 */
@RestController
@RequestMapping("/buy/buy0006")
public class BuyProductItemController extends BaseController
{
    @Autowired
    private IBuyProductItemService buyProductItemService;

    /**
     * 查询投产登记列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BuyProductItem buyProductItem)
    {
        startPage();
        List<BuyProductItem> list = buyProductItemService.selectBuyProductItemList(buyProductItem);
        return getDataTable(list);
    }

    /**
     * 导出投产登记列表
     */
    @Log(title = "投产登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyProductItem buyProductItem)
    {
        List<BuyProductItem> list = buyProductItemService.selectBuyProductItemList(buyProductItem);
        ExcelUtil<BuyProductItem> util = new ExcelUtil<BuyProductItem>(BuyProductItem.class);
        util.exportExcel(response, list, "投产登记数据");
    }

    /**
     * 获取投产登记详细信息
     */
    @GetMapping(value = "/{iD}")
    public AjaxResult getInfo(@PathVariable("iD") Long iD)
    {
        return success(buyProductItemService.selectBuyProductItemByID(iD));
    }

    /**
     * 新增投产登记
     */
    @Log(title = "投产登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyProductItem buyProductItem)
    {
        return toAjax(buyProductItemService.insertBuyProductItem(buyProductItem));
    }

    /**
     * 修改投产登记
     */
    @Log(title = "投产登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyProductItem buyProductItem)
    {
        return toAjax(buyProductItemService.updateBuyProductItem(buyProductItem));
    }

    /**
     * 删除投产登记
     */
    @Log(title = "投产登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{iDs}")
    public AjaxResult remove(@PathVariable Long[] iDs)
    {
        return toAjax(buyProductItemService.deleteBuyProductItemByIDs(iDs));
    }

    @PostMapping("/importData")
    public AjaxResult importBatch(MultipartFile file) throws Exception
    {
        ExcelUtil<BuyProductItemImport> util = new ExcelUtil<>(BuyProductItemImport.class);
        List<BuyProductItemImport> list = util.importExcel(file.getInputStream());
        buyProductItemService.batchSave(list);
        return toAjax(1);
    }
}
